package currentment.printOrder;

import java.util.concurrent.CountDownLatch;

public class PrintInOrder_CountDownLatch {
    // 三个线程交替打印
    private CountDownLatch cd = new CountDownLatch(2);

    public void print(int target) {
        while (true) {
            if (cd.getCount() % 3 == target) {
                System.out.println(Thread.currentThread().getName());
                cd.countDown();
                break;
            }
        }
    }
    public static void main(String[] args) {
        PrintInOrder_CountDownLatch threadInorder = new PrintInOrder_CountDownLatch();
        new Thread(()->threadInorder.print(2),"A").start();
        new Thread(()->threadInorder.print(1),"B").start();
        new Thread(()->threadInorder.print(0),"C").start();
    }
}
